use "Data.dta", clear

* reversing support var for abortion
replace support = 2 if support==1 & topic==7
replace support = 1 if support==0 & topic==7
replace support = 0 if support==2 & topic==7

* three category political knowledge var
recode pol_know (0 1=1) (2 3=2) (4 5=3), g(pk3)


** Figure 1
recode support (.=2), g(re_support)


* Infrastructure bill
catplot treatment re_support if topic==1, recast(bar) percent(treatment) asyvar ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Infrastructure bill") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0)) scheme(plotplain)

graph save "infrastructure", replace


* min wage
catplot treatment re_support if topic==2, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Raise the minimum wage") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "min_wage", replace


* estate tax
catplot treatment re_support if topic==3, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Repeal the estate tax") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "estate_tax", replace


* Capital gains tax
catplot treatment re_support if topic==4, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Capital gains tax = income tax") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "cg_tax", replace

* Border security
catplot treatment re_support if topic==5, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Tighten border security") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "border_security", replace


* Transgender in military
catplot treatment re_support if topic==6, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Allow transgender in military") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "trans_mil", replace



* abortion
catplot treatment re_support if topic==7, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Keep Roe v. Wade") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "Control" 2 "Treatment")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "abortion", replace

* Vaccine mandates
catplot treatment re_support if topic==8, recast(bar) percent(treatment) asyvar scheme(plotplainblind) ///
bar(1, color(black) fintensity(inten80)) ///
bar(2, color(gray) fintensity(inten80)) ///
ytitle("") ///
ylabel(0(25)100, labcolor(gray) ) ///
yscale(range(0 100.1) lc(gray)) ///
title("Vaccine mandates") ///
var1opts(label(labsize(small) labcolor(gray)) relabel(1 "No DK-Option" 2 "DK-Option")) ///
var2opts(label(labsize(small) labcolor(gray)) relabel(1 "Oppose" 2 "Support" 3 "DK/skip")) legend(cols(2) ) ///
graphregion(margin(0.75 0.75 0.75 0.75)) plotregion(margin(0 0 0 0))

graph save "vaccine", replace


grc1leg2 "infrastructure" "min_wage" "estate_tax" "cg_tax" "border_security" "trans_mil" "abortion" "vaccine",  labsize(vsmall) position(6) scheme(plotplain) r(4)  ysize(5) xsize(5) legend("vaccine")

graph export "figure1.pdf",  replace


* Table D1
reg dk i.treatment##i.pol_know i.topic i.round, cluster(respondent_id)
outreg2 using table_D1,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab replace
	
margins, dydx(treatment) at(pol_know=(0(1)5))

** Figure 2
marginsplot, xlabel(, nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(10) scheme(plotplain) title("") xtitle("# correct answers to factual questions about politics") ytitle("Treatment effect", size(medlarge) color("gray")) ylabel(0(.1).32, labsize(medsmall) labcolor(gray)) xscale(r(-.2 5.2))

graph export "figure2.pdf",  replace

su sure
g sure_sd=(sure-`r(mean)')/`r(sd)'

* Table D2
reg sure_sd i.treatment##i.topic i.round, cluster(respondent_id)
outreg2 using table_D2,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab replace

margins, dydx(treatment) over(topic)

* Figure 3
mplotoffset, offset(0.1) xlabel(1 `""Infrastructure" "bill""' 2 `""Minimum" "wage""' 3 "Estate tax" 4 `""Capital gains" "tax""' 5 `""Border" "security""' 6 `""Transgender in" "military""' 7 "Abortion" 8 `""Covid" "vaccines""' , nogrid labsize(medsmall) labcolor(gray)) plotopts(msym(O) msize(medlarge) mlcolor("black") mfcolor("black")) recast(scatter) recastci(rspike) ci1opt(color(black) lwidth(medthick)) xsize(7.5) scheme(plotplain) xtitle("") ytitle("Treatment effect (standardized)", size(medlarge) color("gray")) title("") ylabel(0(.2).65, labsize(medsmall) labcolor(gray)) xscale(r(0.8 8.2))

graph export "figure3.pdf",  replace




** Table D3
reg support i.treatment i.topic i.round, cluster(respondent_id)
outreg2 using table_D3,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab replace

reg support i.treatment##i.topic i.round, cluster(respondent_id)
outreg2 using table_D3,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab append

margins, at(topic=(1(1)8) treatment=(0 1) )

* Figure 4
mplotoffset, offset(0.1)  xlabel(1 `""Infrastructure" "bill""' 2 `""Minimum" "wage""' 3 "Estate tax" 4 `""Capital gains" "tax""' 5 `""Border" "security""' 6 `""Transgender in" "military""' 7 "Abortion" 8 `""Covid" "vaccines""' , nogrid labsize(medsmall) labcolor(gray))  recast(scatter) recastci(rspike) xsize(7.5) scheme(plotplain) ylab(0.5(0.1).9, labsize(medsmall) labcolor(gray)) yscale(r(0.48 0.9)) yline(0.5) xtitle("") ytitle("Policy support", size(medlarge) color("gray")) title("") ///
plot1opts(msymbol(O) mcolor(black))  /// marker for first line
 ci1opts(color(black))  ///
plot2opts(msymbol(O) mcolor(gray)) /// marker for second line
ci2opts(color(gray))   ///
 legend(pos(6) col(2) title("") order(3 4) label(3 "No DK-option") label(4 "DK-option") )
graph export "figure4.pdf",  replace

* Table D4
reg support i.treatment##i.pk3 i.round if topic==1, cluster(respondent_id)
outreg2 using table_D4,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab replace

		foreach n of numlist 2/8 {
reg support i.treatment##i.pk3 i.round if topic==`n', cluster(respondent_id)
outreg2 using table_D4,  word  bd(3) sd(3) rd(3) alpha(0.01, 0.05, 0.1) symbol(**, *, +)  lab append
		}		
		

		* Figure 5
foreach n of numlist 1/8 {
reg support i.treatment##i.pk3 i.round if topic==`n', cluster(respondent_id)
margins, at(pk3=(1 2 3) treatment=(0 1)) saving("h2b_topic`n'", replace)

preserve
use "h2b_topic`n'", clear
g topic=`n'
save "h2b_topic`n'", replace
restore

}

preserve
use "h2b_topic1", clear

foreach n of numlist 2/8 {
append using "h2b_topic`n'"
}

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

* add a little "jitter"
replace _at2=.90 if _at2==1 & _at1==0
replace _at2=1.90 if _at2==2 & _at1==0
replace _at2=2.90 if _at2==3 & _at1==0


replace _at2=1.1 if _at2==1 & _at1==1
replace _at2=2.1 if _at2==2 & _at1==1
replace _at2=3.1 if _at2==3 & _at1==1


twoway ///
(scatter _margin _at2 if _at1==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter _margin _at2 if _at1==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==0,  lcolor(black)  lwidth(medthick)) ///
(rspike _ci_lb _ci_ub _at2 if _at1==1, lcolor(gray)  lwidth(medthick)), ///
by(topic, r(1) note("") title("", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) legend(pos(6) col(2) title("")  order(1 2) label(1 "No DK-option") label(2 "DK-option")) xlabel(1 "Low" 2 "Med" 3 "High", labsize(medsmall)  labcolor(gray) tlength(0.5)) xtick(1 2 3) ylabel(0.3(.1)0.9, labsize(medsmall) labcolor(gray)) xtitle("Political knowledge", size(medsmall) color(gray)) ytitle("Policy support", size(medsmall) color(gray)) xsize(8)
graph export "figure5.pdf",  replace

restore


* Figure 6
preserve
foreach n of numlist 1/8 {
reg support i.treatment##i.pk3 i.round if topic==`n', cluster(respondent_id)
margins, at(pk3=(1 2 3) treatment=(0 1)) post
xlincom 1._at-3._at, post

esttab, ci

mat ci`n'= r(coefs)

reg support i.treatment##i.pk3 i.round if topic==`n', cluster(respondent_id)
margins, at(pk3=(1 2 3) treatment=(0 1)) post
xlincom 4._at-6._at, post

esttab, ci

mat cit`n'= r(coefs)


reg support i.treatment##i.pk3 i.round if topic==`n', cluster(respondent_id)
margins, at(pk3=(1 2 3) treatment=(0 1)) post
xlincom ((4._at-6._at)-(1._at-3._at)), post

esttab, se

mat did`n'= r(coefs)

}
mat ci = ci1\ci2\ci3\ci4\ci5\ci6\ci7\ci8\cit1\cit2\cit3\cit4\cit5\cit6\cit7\cit8

mat list ci

sort respondent_id topic

keep in 1/16

keep topic topic2

g treatment=0 
replace treatment=1 in 9/16

svmat double ci, name(temp)
ren temp1 margin
ren temp2 lb
ren temp3 ub
drop temp4

mat did = did1\did2\did3\did4\did5\did6\did7\did8

mat list did

svmat double did, name(temp)
ren temp1 did_est
ren temp2 did_se
ren temp3 did_p

label define topiclab_alt2 1 "Infrastructure" 2 "Min wage" 3 "Estate tax" 4 "CG tax" 5 "Border sec" 6 "Transgender" 7 "Abortion" 8 "Covid"
label values topic topiclab_alt2

sort topic treatment
g hline=ub+0.03 if treatment==1
replace hline=hline[_n+1] if hline==.

g temp=ub+0.03 if treatment==0
replace temp=temp[_n-1] if temp==.

replace hline=temp if topic==3 | topic==4 | topic==5

drop temp 

g dropl=hline
replace dropl=hline+0.0012 if treatment==0
replace dropl=hline-0.01 if treatment==1

** labels
* slope coefficient
su did_est if treatment==0 & topic==1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g dydx_t="`margin_3f'" if treatment==0 & topic==1

foreach n of numlist 2/8 {
	su did_est if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace dydx_t="`margin_3f'" if treatment==0 & topic== `n'
}


* se
su did_se if treatment==0 & topic== 1
local margin_3f : di %9.3f r(mean)
di `margin_3f'
g se_t="(`margin_3f')" if treatment==0 & topic==1


foreach n of numlist 2/8 {
	su did_se if treatment==0 & topic== `n'
	local margin_3f : di %9.3f r(mean)
	replace se_t="(`margin_3f')" if treatment==0 & topic== `n'
}

replace se_t = subinstr(se_t, " ", "", .)

g lab_t=dydx_t+" "+se_t

g z=0
g o=1
g x=0.08
g x2=0.14
g y_h=hline+0.04
g y_h2=hline+0.02

twoway ///
(scatter margin treatment if treatment==0, msymbol(O) mcolor(black) lcolor(black)) ///
(scatter margin treatment if treatment==1, msymbol(O) mcolor(gray) lcolor(gray) lpattern(solid)) ///
(rspike lb ub treatment if treatment==0,  lcolor(black)  lwidth(medthick)) ///
(rspike lb ub treatment if treatment==1, lcolor(gray)  lwidth(medthick)) ///
 (line  hline treatment ,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl z,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (line  dropl o,  lw(medthick)  mc(none) lc(black) lp(solid)) ///
 (scatter y_h x2, ms(none) mla(dydx_t) mlabcolor(black) mlabsize(medsmall)) ///
 (scatter y_h2 x, ms(none) mla(se_t) mlabcolor(black) mlabsize(medsmall)), ///
by(topic, r(1) legend(off) note("") title("", size(large) position(11))) subtitle(,  size(medsmall)) ///
scheme(plotplain) yline(.5) xtick(0 1) xscale(r(-0.2 1.2)) xlabel(0 "Control" 1 "Treat.", labsize(medsmall)  labcolor(gray) tlength(0.5)) ylabel(-0.3(.1)0.3, labsize(medsmall) labcolor(gray) format(%3.1f)) xtitle("", size(medsmall) color(gray)) ytitle("", size(medsmall) color(gray)) xsize(8)

graph export "figure6.pdf",  replace

restore
